<!--
 * @Author: Dorange.Wang
 * @Date: 2021-07-23 10:50:47
 * @LastEditors: your name
 * @LastEditTime: 2021-07-23 18:24:39
 * @Description: file content
-->
<!DOCTYPE html>
<html>
<head>
    <meta
            charset="UTF-8"
            name="viewport"
            content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=no"
    />
    <title>index</title>
    <script src="./dsbridge.js"></script>
    <link
            rel="stylesheet"
            href="https://cdn.jsdelivr.net/npm/vant@2.12/lib/index.css"
    />
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
    <script src="https://cdn.jsdelivr.net/npm/vant@2.12/lib/vant.min.js"></script>
    <script>
      const HC = {
        BMAP: {
          init: function(OBJECT) {
            const { success } = OBJECT;
            dsBridge.call("BMAP.init","v2MQpiCy4EzOmkbMEVxMz01vnjGeuXL2", function (v) {
              if (true) {
                success &&
                  success({
                    data: v,
                  });
              }
            })
          },
          start: function(OBJECT) {
            const { success } = OBJECT;
            dsBridge.call("BMAP.start","", function (v) {
              if (true) {
                success &&
                  success({
                    data: v,
                  });
              }
            })
          },
          stop: function(OBJECT) {
            const { success } = OBJECT;
            dsBridge.call("BMAP.stop","", function (v) {
              if (true) {
                success &&
                  success({
                    data: v,
                  });
              }
            })
          },
        },
        NATIVE: {
          getVersion: function(OBJECT) {
            const { success } = OBJECT;
            dsBridge.call("BMAP.init","v2MQpiCy4EzOmkbMEVxMz01vnjGeuXL2", function (v) {
              if (true) {
                success &&
                  success({
                    data: v,
                  });
              }
              console.log("HC.NATIVE.getVersion");
            })

          },
          getVersionSync: function() {
            console.log("HC.NATIVE.getVersionSync");
          },
          update: function(OBJECT) {
            const path = OBJECT;
            console.log("HC.NATIVE.update");
            return "success";
          },
        },
        APP: {
          getVersion: function(OBJECT) {
            const { success, fail } = OBJECT;
            if (true) {
              success &&
                success({
                  data: "result",
                });
            } else {
              fail &&
                fail({
                  error: "404",
                });
            }
            console.log("HC.APP.getVersion");
          },
          getVersionSync: function() {
            console.log("HC.APP.getVersionSync");
          },
          update: function(OBJECT) {
            const path = OBJECT;
            console.log("HC.APP.update");
            return "success";
          },

          getLang: function(OBJECT) {
            const { success } = OBJECT;
            if (true) {
              success &&
                success({
                  lang: "lang",
                });
            }
            console.log("HC.APP.getLang");
          },
          getLangSync: function() {
            console.log("HC.APP.getLangSync");
            return "lang";
          },
        },
        IMAGE: {
          choose: function(OBJECT) {
            const { count, extension, sourceType, success } = OBJECT;
            if (true) {
              success &&
                success({
                  tempFilePaths: ["result"],
                  tempFiles: [
                    {
                      path: "path",
                      size: 0,
                    },
                  ],
                });
              console.log("HC.IMAGE.choose");
            }
          },
          preview: function(OBJECT) {
            const { current, paths, success } = OBJECT;
            if (true) {
              success &&
                success({
                  data: "result",
                });
              console.log("HC.IMAGE.preview");
            }
          },
        },
        VIDEO: {
          choose: function(OBJECT) {
            const { extension, sourceType, success } = OBJECT;
            if (true) {
              success &&
                success({
                  tempFilePaths: ["result"],
                  tempFiles: ["result"],
                  duration: 0,
                  size: 0,
                });
              console.log("HC.VIDEO.choose");
            }
          },
          preview: function(OBJECT) {
            const { path, success } = OBJECT;
            if (true) {
              success &&
                success({
                  data: "result",
                });
              console.log("HC.VIDEO.preview");
            }
          },
        },
        FILE: {
          choose: function(OBJECT) {
            const { count, extension, success } = OBJECT;
            if (true) {
              success &&
                success({
                  tempFilePaths: ["result"],
                  tempFiles: [
                    {
                      path: "path",
                      size: 0,
                    },
                  ],
                });
              console.log("HC.FILE.choose");
            }
          },
          download: function(OBJECT) {
            const { paths, success } = OBJECT;
            if (true) {
              success &&
                success({
                  localPath: "result",
                });
              console.log("HC.FILE.download");
            }
          },
        },
        AUDIO: {
          startRecord: function(OBJECT) {
            const { success } = OBJECT;
            if (true) {
              success &&
                success({
                  data: "result",
                });
              console.log("HC.AUDIO.startRecord");
            }
          },
          endRecord: function(OBJECT) {
            const { success } = OBJECT;
            if (true) {
              success &&
                success({
                  tempFilePaths: ["result"],
                  tempFiles: ["result"],
                  duration: 0,
                  size: 0,
                });
              console.log("HC.AUDIO.endRecord");
            }
          },
          play: function(OBJECT) {
            const { path, success } = OBJECT;
            if (true) {
              success &&
                success({
                  data: "result",
                });
              console.log("HC.AUDIO.play");
            }
          },
        },
        CAMERA: {
          scanCode: function(OBJECT) {
            const { sourceType, scanType, success } = OBJECT;
            if (true) {
              success &&
                success({
                  result: "result",
                  scanType: "result",
                });
            }
            console.log("HC.CAMERA.scanCode");
          },
        },
        SQLITE: {
          execute: function(OBJECT) {
            const { database, sql, success, fail, complete } = OBJECT;
            console.log("run HC.SQLITE.execute");
            console.log("params:", database, sql);
            if (true) {
              success &&
                success({
                  data: "execute result",
                });
            } else {
              fail && fail("error message");
            }
            complete && complete();
          },
          executeSync: function(OBJECT) {
            console.log("HC.SQLITE.executeSync");
            return "data";
          },
        },
        MQTT: {
          subscribe: function(OBJECT) {
            const {
              address,
              port,
              username,
              password,
              topics,
              success,
              fail,
              complete,
            } = OBJECT;

            if (true) {
              success &&
                success({
                  data: "execute result",
                });
            } else {
              fail && fail("error message");
            }
            complete && complete();
            console.log("HC.MQTT.subscribe");
          },
          unsubscribe: function(OBJECT) {
            const { success, fail, complete } = OBJECT;

            if (true) {
              success &&
                success({
                  data: "execute result",
                });
            } else {
              fail && fail("error message");
            }
            complete && complete();
            console.log("HC.MQTT.unsubscribe");
          },
          onReceive: function(Function) {
            const fn = Function;
            console.log("HC.MQTT.onReceive");
            return "HC.MQTT.onReceive";
          },
        },
        NOTIFY: {
          onClick: function(Function) {
            const fn = Function;
            console.log("HC.NOTIFY.onClick");
            return "HC.NOTIFY.onClick";
          },
        },
        WEBVIEW: {
          open: function(Object) {
            const { path, success } = Object;
            if (true) {
              success &&
                success({
                  data: "result",
                });
            }
            console.log("HC.WEBVIEW.open");
          },
          close: function() {
            console.log("HC.WEBVIEW.close");
            return "HC.WEBVIEW.close";
          },
          onShow: function(OBJECT) {
            console.log("HC.WEBVIEW.onShow");
            return "HC.WEBVIEW.onShow";
          },
          onBack: function(OBJECT) {
            console.log("HC.WEBVIEW.onBack");
            return "HC.WEBVIEW.onBack";
          },
        },
      };

    </script>
</head>

<body>
<div id="app">
    <van-cell value="BMAP接口"></van-cell>
    <van-row gutter="5">
        <van-col>
            <van-button type="primary" @click="onClickBMAPInit"
            >init
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickBMAPStart"
            >start
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickBMAPStop"
            >stop
            </van-button
            >
        </van-col>
    </van-row>
    <van-cell value="NATIVE接口"></van-cell>
    <van-row gutter="5">
        <van-col>
            <van-button type="primary" @click="onClickNATIVEGetVersion"
            >getVersion
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickNATIVEGetVersionSync"
            >getVersionSync
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickNATIVEUpdate"
            >Update
            </van-button
            >
        </van-col>
    </van-row>
    <van-cell value="APP接口"></van-cell>
    <van-row gutter="5">
        <van-col>
            <van-button type="primary" @click="onClickAPPGetVersion"
            >getVersion
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickAPPGetVersionSync"
            >getVersionSync
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickAPPUpdate"
            >update
            </van-button
            >
        </van-col>
    </van-row>
    <van-row gutter="5">
        <van-col>
            <van-button type="primary" @click="onClickGetLang"
            >getLang
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickGetLangSync"
            >getLangSync
            </van-button
            >
        </van-col>
    </van-row>

    <van-cell value="IMAGE接口"></van-cell>
    <van-row gutter="5">
        <van-col>
            <van-button type="primary" @click="onClickIMAGEchoose"
            >choose
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickIMAGEpreview"
            >preview
            </van-button
            >
        </van-col>
    </van-row>

    <van-cell value="VIDEO接口"></van-cell>
    <van-row gutter="5">
        <van-col>
            <van-button type="primary" @click="onClickVIDEOchoose"
            >choose
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickVIDEOpreview"
            >preview
            </van-button
            >
        </van-col>
    </van-row>

    <van-cell value="FILE接口"></van-cell>
    <van-row gutter="5">
        <van-col>
            <van-button type="primary" @click="onClickFILEchoose"
            >choose
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickFILEdownload"
            >download
            </van-button
            >
        </van-col>
    </van-row>

    <van-cell value="AUDIO接口"></van-cell>
    <van-row gutter="5">
        <van-col>
            <van-button type="primary" @click="onClickAUDIOstartRecord"
            >startRecord
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickAUDIOendRecord"
            >endRecord
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickAUDIOplay">play</van-button>
        </van-col>
    </van-row>

    <van-cell value="CAMERA接口"></van-cell>
    <van-button type="primary" @click="onClickCAMERAscanCode"
    >scanCode
    </van-button
    >

    <van-cell value="SQLITE接口"></van-cell>
    <van-row gutter="5">
        <van-col>
            <van-button type="primary" @click="onClickSQLITEexecute"
            >execute
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickSQLITEexecuteSync"
            >executeSync
            </van-button
            >
        </van-col>
    </van-row>

    <van-cell value="MQTT接口"></van-cell>

    <van-row gutter="5">
        <van-col>
            <van-button type="primary" @click="onClickMQTTSubscribe"
            >subscribe
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickMQTTunsubscribe"
            >unsubscribe
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickMQTTonReceive"
            >onReceive
            </van-button
            >
        </van-col>
    </van-row>

    <van-cell value="NOTIFY接口"></van-cell>
    <van-button type="primary" @click="onClickNOTIFYonClick"
    >onClick
    </van-button
    >

    <van-cell value="WEBVIEW接口"></van-cell>
    <van-row gutter="5">
        <van-col>
            <van-button type="primary" @click="onClickWEBVIEWopen"
            >open
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickWEBVIEWclose"
            >close
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickWEBVIEWOnShow"
            >onShow
            </van-button
            >
        </van-col>
        <van-col>
            <van-button type="primary" @click="onClickWEBVIEWOnBack"
            >onBack
            </van-button
            >
        </van-col>
    </van-row>
</div>

<script>
      new Vue({
        el: "#app",
        data() {
          return {};
        },
        methods: {
          onClickBMAPInit() {
            HC.BMAP.init({
              success: function() {
                console.log("success");
                vant.Toast("success");
              },
            });
          },
          onClickBMAPStart() {
            HC.BMAP.start({
              success: function() {
                console.log("success");
                vant.Toast("success");
              },
            });
          },
          onClickBMAPStop() {
            HC.BMAP.stop({
              success: function() {
                console.log("success");
                vant.Toast("success");
              },
            });
          },
          onClickNATIVEGetVersion() {
            HC.NATIVE.getVersion({
              success: function() {
                console.log("success");
                vant.Toast("success");
              },
            });
          },
          onClickNATIVEGetVersionSync() {
            // 无参数
          },
          onClickNATIVEUpdate() {
            HC.NATIVE.update({
              path: "path",
            });
            vant.Toast(HC.NATIVE.update());
          },
          onClickAPPGetVersion() {
            HC.APP.getVersion({
              success: function(res) {
                console.log(res);
                vant.Toast("success");
              },
              fail: function(err) {
                console.log(err.error);
                vant.Toast("fail");
              },
            });
          },
          onClickAPPGetVersionSync() {
            // 无参数
          },
          onClickAPPUpdate() {
            HC.APP.update({
              path: "path",
            });
            vant.Toast(HC.APP.update());
          },

          onClickGetLang() {
            HC.APP.getLang({
              success: function(res) {
                console.log(res.lang);
                vant.Toast("success:   " + res.lang);
              },
            });
          },
          onClickGetLangSync() {
            const lang = HC.APP.getLangSync();
            console.log("当前系统语言编码：", lang);
            vant.Toast("当前系统语言编码：" + lang);
          },

          onClickIMAGEchoose() {
            HC.IMAGE.choose({
              count: 6, //默认9
              extension: ["png"],
              sourceType: ["album"], //从相册选择
              success: function(res) {
                console.log(res.tempFilePaths);
                console.log(res.tempFiles);
                vant.Toast(
                  "success:\n" +
                    "tempFilePaths:  " +
                    res.tempFilePaths +
                    "\n" +
                    "tempFiles:   " +
                    res.tempFiles
                );
              },
            });
          },

          onClickIMAGEpreview() {
            HC.IMAGE.preview({
              current: 6,
              paths: ["ccccc.png"],
              success: function() {
                console.log("success");
                vant.Toast("success");
              },
            });
          },
          onClickVIDEOchoose() {
            HC.VIDEO.choose({
              count: 6, //默认9
              extension: ["png"],
              sourceType: ["album"], //从相册选择
              success: function(res) {
                console.log(res.tempFilePaths);
                console.log(res.tempFiles);
                console.log(res.duration);
                console.log(res.size);
                vant.Toast(
                  "success:\n" +
                    "tempFilePaths:  " +
                    res.tempFilePaths +
                    "\n" +
                    "tempFiles:   " +
                    res.tempFiles +
                    "\n" +
                    "duration:   " +
                    res.duration +
                    "\n" +
                    "size:   " +
                    res.size
                );
              },
            });
          },
          onClickVIDEOpreview() {
            HC.VIDEO.preview({
              path: "ccccc.mp4",
              success: function() {
                console.log("success");
                vant.Toast("success");
              },
            });
          },
          onClickFILEchoose() {
            HC.FILE.choose({
              count: 6, //默认9
              extension: ["png", "pdf"],
              success: function(res) {
                console.log(res.tempFilePaths);
                console.log(res.tempFiles);
                vant.Toast(
                  "success:\n" +
                    "tempFilePaths:  " +
                    res.tempFilePaths +
                    "\n" +
                    "tempFiles:   " +
                    res.tempFiles
                );
              },
            });
          },
          onClickFILEdownload() {
            HC.FILE.download({
              path: "",
              success: function(res) {
                console.log(res.localPath);
                vant.Toast("success:　" + res.localPath);
              },
            });
          },
          onClickAUDIOstartRecord() {
            HC.AUDIO.startRecord({
              success: function() {
                console.log("success");
                vant.Toast("success");
              },
            });
          },
          onClickAUDIOendRecord() {
            HC.AUDIO.endRecord({
              success: function(res) {
                console.log(res.tempFilePaths);
                console.log(res.tempFiles);
                console.log(res.duration);
                console.log(res.size);
                vant.Toast(
                  "success:\n" +
                    "tempFilePaths:  " +
                    res.tempFilePaths +
                    "\n" +
                    "tempFiles:   " +
                    res.tempFiles +
                    "\n" +
                    "duration:   " +
                    res.duration +
                    "\n" +
                    "size:   " +
                    res.size
                );
              },
            });
          },
          onClickAUDIOplay() {
            HC.AUDIO.play({
              path: "ccccc.mp3",
              success: function() {
                console.log("success");
                vant.Toast("success");
              },
            });
          },
          onClickCAMERAscanCode() {
            HC.CAMERA.scanCode({
              sourceType: ["album", "camera"],
              scanType: ["qrCode", "barCode"],
              success: function(res) {
                console.log(res.result);
                console.log(res.scanType);
                vant.Toast(
                  "success:\n" +
                    "result:  " +
                    res.result +
                    "\n" +
                    "scanType:   " +
                    res.scanType
                );
              },
            });
          },
          onClickSQLITEexecute() {
            HC.SQLITE.execute({
              database: "xxxx.db",
              sql: "select * from xxxxx",
              success: function(res) {
                console.log("success", res.data);
                vant.Toast("success  \n" + res.data);
              },
              complete: function() {
                console.log("complete");
              },
            });
          },
          onClickSQLITEexecuteSync() {
            const data = HC.SQLITE.executeSync({
              database: "",
              sql: "",
            });
            console.log("HC.SQLITE.executeSync result", data);
            vant.Toast("HC.SQLITE.executeSync \nresult: " + data);
          },
          onClickMQTTSubscribe() {
            HC.MQTT.subscribe({
              address: "",
              port: "",
              username: "",
              password: "",
              topics: [],
              success: function() {
                console.log("success");
                vant.Toast("success");
              },
              fail: function() {},
              complete: function() {},
            });
          },
          onClickMQTTunsubscribe() {
            HC.MQTT.unsubscribe({
              success: function() {
                console.log("success");
                vant.Toast("success");
              },
              fail: function() {},
              complete: function() {},
            });
          },
          onClickMQTTonReceive() {
            HC.MQTT.onReceive(function(data) {
              console.log(data);
            });
            vant.Toast("success");
          },
          onClickNOTIFYonClick() {
            HC.NOTIFY.onClick(function(data) {
              console.log(data);
            });
            vant.Toast("success");
          },
          onClickWEBVIEWopen() {
            HC.WEBVIEW.open({
              path: "/#/workbench?name=abc",
              success: function() {
                console.log("open success");
                vant.Toast("open success");
              },
            });
          },
          onClickWEBVIEWclose() {
            vant.Toast(HC.WEBVIEW.close());
          },
          onClickWEBVIEWOnShow() {
            vant.Toast(HC.WEBVIEW.onShow());
          },
          onClickWEBVIEWOnBack() {
            vant.Toast(HC.WEBVIEW.onBack());
          },
        },
      });

</script>
</body>

<style>
    #app {
      margin-left: 6px;
    }

    .van-col {
      margin-top: 3px;
      margin-bottom: 10px;
    }

</style>
</html>
